#include "com.hpp"

int main()
{
    // 1.创建共同的key值
    key_t key = ftok(PATH_NAME, PROJ_ID);
    if (key < 0)
    {
        perror("ftok error");
        exit(1);
    }

    Log("create key done", DEBUG) << "client key: " << key << endl;

    // 2.获取共享内存
    int shmid = shmget(key, SHM_SIZE, 0);
    if (shmid < 0)
    {
        perror("shmget error");
        exit(2);
    }

    Log("create shm done", DEBUG) << "client shmid: " << shmid << endl;

    // 3.关联共享内存
    char* shmaddr = (char*)shmat(shmid, nullptr, 9);
    if (shmaddr == nullptr)
    {
        perror("shmat error");
        exit(3);
    }

    Log("attach shm done", DEBUG) << "client shmid: " << shmid << endl;
    sleep(10);

    // 这里开始通信

    // 4.去关联
    int n = shmdt(shmaddr);
    Log("detach shm done", DEBUG) << "client shmid: " << shmid << endl;

    // client不需要删除共享内存
    return 0;
}